package cn.tansanqinger.basics;

import sun.misc.Unsafe;

import java.lang.reflect.Field;

class Singleton{
    private Singleton(){
        System.out.println("构造方法被私有化");
    }
    public void msg(){
        System.out.println("www.tansanqinger.cn");
    }
}
public class Test4 {
    public static void main(String[] args) {
        try{
            Field unsafe = Unsafe.class.getDeclaredField("theUnsafe");
            unsafe.setAccessible(true);
            Unsafe unsafe1 = (Unsafe) unsafe.get(null);
            Singleton singleton = (Singleton) unsafe1.allocateInstance(Singleton.class);
            singleton.msg();
        } catch (Exception e){}
    }
}
